/*************************************************************************
 * File Name:    1698_bipartite.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sun 20 Oct 2013 04:59:38 PM CST
 * 
 * Description:  
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#define MAXROW 1001
#define MAXCOL 360

int week[8], link[MAXROW];
char visited[MAXROW], matrix[MAXROW][MAXCOL];

int
dfs (int vex, int m)
{
    int i;

    for (i = 1; i <= m; ++i) {
        if (!visited[i] && matrix[vex][i]) {
            visited[i] = 1;
            if (link[i] == 0 || dfs (link[i], m)) {
                link[i] = vex;
                return 1;
            }
        }
    }
    return 0;
}

int
main (void)
{
    int T, n;
    int r, D, W, beg, maxw, sum, ans;

    scanf ("%d", &T);
    while (T--) {
        beg = 1;
        maxw = sum = 0;
        memset (matrix, 0, sizeof (matrix));
        scanf ("%d", &n);

        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= 7; ++j) scanf ("%d", &week[j]);
            scanf ("%d%d", &D, &W);
            for (int j = beg; j < beg + D; ++j) {
                for (int k = 1; k <= 7; ++k) {
                    if (week[k]) for (r = 0; r < W; ++r) matrix[j][k + r * 7] = 1;
                }
            }
            beg += D;
            sum += D;
            if (W * 7 > maxw) maxw = W * 7;
        }

        ans = 0;
        memset (link, 0, sizeof (link));
        for (i = 1; i < beg; ++i) {
            memset (visited, 0, sizeof (visited));
            if (dfs (i, maxw)) ++ans;
        }
        if (ans != sum) printf ("No\n");
        else printf ("Yes\n");
    }
    return 0;
}
